from symbol import pass_stmt

import requests
from loguru import logger

from config import ENV_MAP, ENV, JsonPath


class Base:
    HOST = ""

    def send_request(self,api_name,data:dict)->requests.Response:
        if self.HOST:
            data.update({"url":self.HOST+data.get("url")})

        logger.info(f"接口 - {api_name} - 请求参数为:{data}")
        response = requests.request(**data)
        logger.info(f"接口 - {api_name} - 响应信息为:{response.text}")
        return response


class Login(Base):
    def __init__(self):
        self.HOST = ENV.HOST
        self.server_token = self._server_login()
        self.path = JsonPath()
        self.user_token = self._user_login()
    def _server_login(self):
        data = {
            "url": "/adminapi/login?username=admin&password=123123",
            "method": "get"
        }
        return self.send_request(self._server_login.__name__,data).json()["data"]["token"]

    def _user_login(self):
        data = {
            "url": "/api/login?username=abcd&password=123456&mobile=&mobile_code=&mobile_key=",
            "method": "get"
        }
        return self.send_request(self._user_login.__name__,data).json()["data"]["token"]

# if __name__ == '__main__':
#     login=Login()
#     print(login._user_login())
